<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <Canvas id="c1" width="600" height="400">
        当前浏览器不支持canvas，请下载最新的浏览器
    </Canvas>

    <script>
        /** @type {HTMLCanvasElement}**/
        var c1 = document.getElementById("c1");
        if(!c1.getContext){
            console.log('当前浏览器不支持canvas，请下载最新浏览器')
        }
        var ctx = c1.getContext('2d');

        let img = new Image();
        img.src = './img/p1.webp';
        img.onload = function(){
            //第一种方式，参数1图片对象，参数2渲染到画布水平位置，参数3渲染到垂直位置
            //ctx.drawImage(img,0,0);
            //第二种方式 缩放图片大小到600*400
            //ctx.drawImage(img,0,0,600,400);
            //50,0,500,500,    起点位置，矩形的宽高
            ctx.drawImage(img,200,0,900,700,0,0,600,400)
        }
    </script>
</body>
</html>